<?php
if(!empty($newsletters))
{?>
	<p><?php echo $paginator->counter(array(
	'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
	));?></p>
	<div class="links index">
		<table cellpadding="0" cellspacing="0">
			<tr>
				<th><?php echo $paginator->sort('id');?></th>
				<th><?php echo $paginator->sort('subject');?></th>
				<th>Status</th>
				<th class="actions"><?php __('Actions');?></th>
			</tr>
			<?php
			$i = 0;
			foreach ($newsletters as $newsletter)
			{
				$class = null;
				if ($i++ % 2 == 0)
				{
					$class = ' class="altrow"';
				}?>
				<tr<?php echo $class;?>>
					<td>
						<?php echo $newsletter['Newsletter']['id']; ?>
					</td>
					<td>
						<?php echo substr($newsletter['Newsletter']['subject'], 0, 100); ?>
					</td>
					<td>
						<?php 
							if(!isset($newsletter['Schedule'][0]['status']))
								echo "Not Scheduled";
							elseif($newsletter['Schedule'][0]['status']==Schedule::PENDING)
								echo "Scheduled for ".$newsletter['Schedule'][0]['date'];
							elseif($newsletter['Schedule'][0]['status']==Schedule::SENDING)
								echo "Sending.."; 
							elseif($newsletter['Schedule'][0]['status']==Schedule::COMPLETED)
								echo "Finished Sending"; 			
						?>
					</td>		
					<td class="actions">
						<?php if(!isset($newsletter['Schedule'][0]['status']) || $newsletter['Schedule'][0]['status']==Schedule::COMPLETED):?>
							<?php echo $html->link(__('Schedule for sending', true), array('action'=>'add', 'controller'=>"schedules",$newsletter['Newsletter']['id'])); ?>
						<?php endif;?>
						<?php echo $html->link(__('View', true), array('action'=>'view', $newsletter['Newsletter']['id'])); ?>
						<?php echo $html->link(__('Edit', true), array('action'=>'edit', $newsletter['Newsletter']['id'])); ?>
						<?php echo $html->link(__('Delete', true), array('action'=>'delete', $newsletter['Newsletter']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $newsletter['Newsletter']['id'])); ?>
						
					</td>
				</tr>
				<?php 
			}//foreache ends here?>
		</table>
	</div>
	<div class="paging">
	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
</div>
<?php
}else
{
	echo __('No newsletter have been created yet.').'<br />';
}?>
<?php echo $html->link(__('Add Newsletter'),'/admin/newsletters/add')?>

